package com.matrix.java.chap_06;

/*
    估算 PI
 */
public class Ex6_14 {
    public static void main(String[] args) {

        System.out.println("i\t\tm(i)");
        for (int i = 1; i <= 901; i+=100) {
            System.out.printf("%d\t\t%.4f%n", i, sum2PI(i));
        }
    }

    private static double sum2PI(int num) {
        double sum = 0;
        for (double j = 1; j <= num; j++) {
            sum+=4*(Math.pow(-1,j+1)/(2*j-1));
        }
        return sum;
    }
}

